﻿using mediaPrime.Controls;
using mediaPrime.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace mediaPrime.Plugin.SystemManagement.Dialogs
{
    /// <summary>
    /// Interaktionslogik für SelectEnumValueDialog.xaml
    /// </summary>
    public partial class SelectEnumValueDialog : MPDialog
    {
        public string Value { get; private set; }

        public SelectEnumValueDialog(List<string> values, string currentValue)
        {
            InitializeComponent();

            var menuList = new List<MPMenuItemBase>();

            foreach (var value in values)
            {
                menuList.Add(new MPMenuItem(value));

            }


            menuList.Add(new MPMenuItemSeparator());
            menuList.Add(new MPMenuItem("Cancel") { Tag = "Cancel" });

            menuControl.ItemsSource = menuList;

            if (string.IsNullOrEmpty(currentValue))
                menuControl.SelectedItem = menuList.LastOrDefault();
            else
                menuControl.SelectedItem = menuList.Where(i => (i is MPMenuItem) && ((i as MPMenuItem).Content == currentValue)).FirstOrDefault();

        }

        private void menuControl_MenuItemClicked(object sender, MPMenuItemClickedEventArgs e)
        {
            if (e.Item is MPMenuItem)
            {
                var item = e.Item as MPMenuItem;
                var tag = item.Tag as string;
                if (tag == "Cancel")
                    DialogResult = false;
                else
                {
                    Value = item.Content;
                    DialogResult = true;
                }
            }
        }
    }

}
